import numpy as np
import pandas as pd
import openpyxl

def flow_to_excel(flow_file, output_excel):
    flow = np.load(flow_file)
    rows, cols, _ = flow.shape

    data = []

    for i in range(0, rows, 4):  # 512 / 128 = 4
        row_data = []
        for j in range(0, cols, 4):
            block = flow[i:i+4, j:j+4]
            avg_flow = np.mean(block, axis=(0, 1))
            row_data.append(f"({avg_flow[0]:.2f}, {avg_flow[1]:.2f})")
        data.append(row_data)

    df = pd.DataFrame(data)
    df.to_excel(output_excel, index=False, header=False)
    print(f"Flow data saved to {output_excel}")

# 示例用法
flow_file = 'E:\\wafer52\\coarse_32nm_flow3\\tr18-tc9.npy'
output_excel = 'E:\\wafer52\\test\\flow_compare\\tr18-tc9.xlsx'  # 如果不需要保存可视化结果，可以设为None
flow_to_excel(flow_file, output_excel)
